-
Notifications
You must be signed in to change notification settings - Fork 665
fix(text/unstable): only strip single trailing newline in dedent #6913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(text/unstable): only strip single trailing newline in dedent #6913
Conversation
Fixes denoland#6831 The dedent function was using `.trimEnd()` which removes ALL trailing whitespace including multiple newlines. This is inconsistent with npm:string-dedent which only removes a single trailing newline. Changes: - Replace `.trimEnd()` with `.replace(/\n[\t ]*$/, "")` to only strip a single trailing newline (with any preceding whitespace on that line) - Updated documentation to reflect the new behavior Before: ```ts dedent\` a \` // returns 'a' (all trailing newlines stripped) ``` After: ```ts dedent\` a \` // returns 'a\n' (only one trailing newline stripped) ```
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6913 +/- ##
==========================================
+ Coverage 94.14% 94.16% +0.01%
==========================================
Files 583 583
Lines 42806 42813 +7
Branches 6815 6815
==========================================
+ Hits 40301 40316 +15
+ Misses 2455 2446 -9
- Partials 50 51 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
kt3k
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks in a good direction. Can you format source code with deno fmt? Also can you add a test case to verify the example in #6831 ?
text/unstable_dedent_test.ts
Outdated
| const result = dedent` | ||
| a | ||
| `; | ||
| assertEquals(result, "a"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case seems already passing with the existing code i.e. it doesn't seem testing what this PR changes. I'm removing this case
kt3k
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Fixes #6831
The
dedentfunction was using.trimEnd()which removes ALL trailing whitespace including multiple newlines. This is inconsistent withnpm:string-dedentwhich only removes a single trailing newline.Changes
.trimEnd()with.replace(/\n[\t ]*$/, "")to only strip a single trailing newline (with any preceding whitespace on that line)Before
After
Testing
The fix ensures consistency with
npm:string-dedent@3.0.2behavior.